/**
 * *************************************
 * Copyright(c)2016 Dingdang Yixia 
 * All Rights Reserved.
 *
 * @File: NoticeServiceImpl.java
 * @Package: com.ddyx.service.impl
 * @Description:
 * 
 * @Version: V1.0
 * @Author: Yidong.Xiang
 * @Date: 2017年8月26日 下午5:18:33
 * 
 * *************************************
 */
package com.ddyx.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ddyx.common.util.ResponseJson;
import com.ddyx.entity.FaceNotice;
import com.ddyx.mapper.FaceNoticeMapper;
import com.ddyx.service.INoticeService;

/**
 * @ClassName: NoticeServiceImpl.java
 * @Module: 
 * @Description: 
 * 
 * @author: Yidong.Xiang
 * @date: 2017年8月26日 下午5:18:33
 * 
 */
@Service("noticeService")
public class NoticeServiceImpl implements INoticeService {

	@Resource
	FaceNoticeMapper faceNoticeMapper;
	/* (non-Javadoc)
	 * @see com.ddyx.service.NoticeService#getLatest(java.lang.String)
	 */
	@Override
	public String getLatest(String now) {
		int total = faceNoticeMapper.countLatestNotice(now);
		if (total<1)
			return ResponseJson.getInstance().toString();
		List<FaceNotice> list = faceNoticeMapper.findLatestNotice(now);
		return ResponseJson.getInstance()
				.setPage(1).setSize(total)
				.setTotal(total)
				.setData(list).toString();//返回有记录的JSON格式文本
	}

	@Override
	public String getLatest(long msec) {
		int total = faceNoticeMapper.countNoticeByMsec(msec);
		if (total<1)
			return ResponseJson.getInstance().toString();
		List<Map<String,Object>> list = faceNoticeMapper.findNoticeByMsec(msec);
		return ResponseJson.getInstance()
				.setPage(1).setSize(total)
				.setTotal(total)
				.setData(list).toString();//返回有记录的JSON格式文本
	}
	/* (non-Javadoc)
	 * @see com.ddyx.service.NoticeService#listActive(int, int)
	 */
	@Override
	public String listActive(int page, int size) {
		int start = 0;
		if(size<1)
			size=20;//默认每页20条
		if(page<1)
			page = 1;//默认第1页
		start = (page-1)*size;
		int total = faceNoticeMapper.countNotice(page, size);
		if (total<1)
			return ResponseJson.getInstance().toString();
		List<FaceNotice> list = faceNoticeMapper.findNotice(start, size);
		return ResponseJson.getInstance()
				.setPage(page).setSize(size).setTotal(total).setData(list).toString();//返回有记录的JSON格式文本
	}

	/* (non-Javadoc)
	 * @see com.ddyx.service.NoticeService#completed(java.lang.String)
	 */
	@Override
	public int completed(String ids) {
		if(ids==null)return 0;
		if("".equals(ids))return 0;
		
		return faceNoticeMapper.updateNoticeStatus(ids);
	}


}
